package control.panel
{
	import events.LoginEvent;
	
	import flash.events.IOErrorEvent;
	
	import view.panel.prompt.AlertButPanel;

	public class AlertButPanelControl extends PanelControl
	{
		
		
		public function AlertButPanelControl()
		{
			initPanel();	
			initListener();
		}
		
		private function initListener():void
		{
			_model.loginModel.addEventListener(LoginEvent.GAMESERVER_FAILED,onGameServerLoginFailed);
			_model.loginModel.addEventListener(LoginEvent.GAMESERVER_FAILED_RELOGIN,onGameServerRelogin);
			_model.netSocket.addEventListener(IOErrorEvent.IO_ERROR,onSocketError);
		}
		
		private function onGameServerRelogin(event:LoginEvent):void
		{
			alert("房间人满，请重新选择房间登陆",event.type);
		}
		
		private function onSocketError(event:IOErrorEvent):void
		{
			alert("游戏服务器连接出错，点击确定返回大厅",event.type);
		}
		
		private function onGameServerLoginFailed(event:LoginEvent):void
		{
			alert("连接服务器失败，点击确定返回大厅",event.type);
		}
		
		private function initPanel():void
		{
			_view.alertButPanel = new AlertButPanel(this);
		}
		
		public function alert(content:String,type:String):void
		{
			if (content)
			{
				_view.alertButPanel.alertBut(content,type);
				_view.alertButPanel.open();
				_control.sceneControl.lockWorld();
			}
		}
		
		public function onYes(type:String):void
		{
			switch (type)
			{
				case IOErrorEvent.IO_ERROR:
				case LoginEvent.GAMESERVER_FAILED:
				case LoginEvent.GAMESERVER_FAILED_RELOGIN:
					_control.sceneControl.switchToHall();
					break;
			}
			_view.alertButPanel.close();
			_control.sceneControl.unlockWorld();
		}
	}
}